package bigdata.api.ticketbiz;

import bigdata.api.ticketbiz.model.*;
import bigdata.api.ticketbiz.response.TicketbizResponse;
import bigdata.api.ticketbiz.service.TicketbizService;
import bigdata.api.weather.service.WeatherService;
import common.utils.gsonutil.GsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 描述:
 *
 * @author 002465
 * @created 2017/7/5 20:22
 * @since v1.0.0
 */
@Controller
@RequestMapping("/ticketbiz")
public class TicketbizController {
    @Autowired
    private TicketbizService ticketbizService;
    private String getJsonp(String callback,Object object){
        String json = object == null?"":GsonUtil.create().toJson(object);
        return new StringBuffer(callback).append("(").append(json).append(")").toString();
    }
    /**
     * @param startDate yyyy-MM-dd
     * @param endDate yyyy-MM-dd
     * @param callback
     * @return
     */
    @RequestMapping(params = { "method=saleCollectByDay" })
    @ResponseBody()
    public String saleCollectByDay(String startDate,String endDate,String callback) {
        TicketbizResponse<SaleCollectModel> response = ticketbizService.saleCollectByDay(startDate, endDate);
        if(response == null) {
            return getJsonp(callback,"调用九天达为空!");
        }
        if(response.isSuccess()){
            return getJsonp(callback,response.getQueryInfoSet());
        }
        return  "";
    }

    /**线下售票统计
     * @param startDate yyyy-MM
     * @param endDate yyyy-MM
     * @param callback
     * @return
     */
    @RequestMapping(params = { "method=saleCollectByMonth" })
    @ResponseBody()
    public String saleCollectByMonth(String startDate,String endDate,String callback) {
        TicketbizResponse<SaleCollectModel> response = ticketbizService.saleCollectByMonth(startDate, endDate);
        if(response == null) {
            return getJsonp(callback,"调用九天达为空!");
        }
        if(response.isSuccess()){
            return getJsonp(callback,response.getQueryInfoSet());
        }
        return  "";
    }

    /**线下售票统计
     * @param startDate yyyy
     * @param endDate yyyy
     * @param callback
     * @return
     */
    @RequestMapping(params = { "method=saleCollectByYear" })
    @ResponseBody()
    public String saleCollectByYear(String startDate,String endDate,String callback) {
        TicketbizResponse<SaleCollectModel> response = ticketbizService.saleCollectByYear(startDate, endDate);
        if(response == null) {
            return getJsonp(callback,"调用九天达为空!");
        }
        if(response.isSuccess()){
            return getJsonp(callback,response.getQueryInfoSet());
        }
        return  "";
    }

    /**线下检票统计
     * @param startDate yyyy-MM-dd
     * @param endDate yyyy-MM-dd
     * @param callback
     * @return
     */
    @RequestMapping(params = { "method=checkCollectByDay" })
    @ResponseBody()
    public String checkCollectByDay(String startDate,String endDate,String callback) {
        TicketbizResponse<CheckCollectModel> response = ticketbizService.checkCollectByDay(startDate, endDate);
        if(response == null) {
            return getJsonp(callback,"调用九天达为空!");
        }
        if(response.isSuccess()){
            return getJsonp(callback,response.getQueryInfoSet());
        }
        return  "";
    }

    /**线下退票统计
     * @param startDate yyyy-MM-dd
     * @param endDate yyyy-MM-dd
     * @param callback
     * @return
     */
    @RequestMapping(params = { "method=returnCollectByDay" })
    @ResponseBody()
    public String returnCollectByDay(String startDate,String endDate,String callback) {
        TicketbizResponse<ReturnCollectModel> response = ticketbizService.returnCollectByDay(startDate, endDate);
        if(response == null) {
            return getJsonp(callback,"调用九天达为空!");
        }
        if(response.isSuccess()){
            return getJsonp(callback,response.getQueryInfoSet());
        }
        return  "";
    }

    /**线下出入口人数统计
     * @param startDate yyyy-MM-dd
     * @param endDate yyyy-MM-dd
     * @param callback
     * @return
     */
    @RequestMapping(params = { "method=exitPersonCollectByDay" })
    @ResponseBody()
    public String exitPersonCollectByDay(String startDate,String endDate,String callback) {
        TicketbizResponse<ExitPersonCollectModel<ExitPersonCollectModelData>> response = ticketbizService.exitPersonCollectByDay(startDate, endDate);
        if(response == null) {
            return getJsonp(callback,"调用九天达为空!");
        }
        if(response.isSuccess()){
            return getJsonp(callback,response.getQueryInfoSet());
        }
        return  "";
    }

    /** 订单来源分析接口
     * @param startDate yyyy-MM-dd
     * @param endDate yyyy-MM-dd
     * @param callback
     * @return
     */
    @RequestMapping(params = { "method=orderResourceCollectByDay" })
    @ResponseBody()
    public String orderResourceCollectByDay(String startDate,String endDate,String callback) {
        TicketbizResponse<OrderResourceCollectModel> response = ticketbizService.orderResourceCollectByDay(startDate, endDate);
        if(response == null) {
            return getJsonp(callback,"调用九天达为空!");
        }
        if(response.isSuccess()){
            return getJsonp(callback,response.getQueryInfoSet());
        }
        return  "";
    }

    /** 游客购票类型分析接口
     * @param startDate yyyy-MM-dd
     * @param endDate yyyy-MM-dd
     * @param callback
     * @return
     */
    @RequestMapping(params = { "method=ticketTypeCollectByDay" })
    @ResponseBody()
    public String ticketTypeCollectByDay(String startDate,String endDate,String callback) {
        TicketbizResponse<TicketTypeCollectModel> response = ticketbizService.ticketTypeCollectByDay(startDate, endDate);
        if(response == null) {
            return getJsonp(callback,"调用九天达为空!");
        }
        if(response.isSuccess()){
            return getJsonp(callback,response.getQueryInfoSet());
        }
        return  "";
    }

    /** 景区免费票数据分析接口
     * @param startDate yyyy-MM-dd
     * @param endDate yyyy-MM-dd
     * @param callback
     * @return
     */
    @RequestMapping(params = { "method=freeTicketCollectByDay" })
    @ResponseBody()
    public String freeTicketCollectByDay(String startDate,String endDate,String callback) {
        TicketbizResponse<FreeTicketCollectModel> response = ticketbizService.freeTicketCollectByDay(startDate, endDate);
        if(response == null) {
            return getJsonp(callback,"调用九天达为空!");
        }
        if(response.isSuccess()){
            return getJsonp(callback,response.getQueryInfoSet());
        }
        return  "";
    }

    /** 客源地购票分析接口
     * @param startDate yyyy-MM-dd
     * @param endDate yyyy-MM-dd
     * @param callback
     * @return
     */
    @RequestMapping(params = { "method=originateCollectByDay" })
    @ResponseBody()
    public String originateCollectByDay(String startDate,String endDate,String callback) {
        TicketbizResponse<OriginateCollectModel> response = ticketbizService.originateCollectByDay(startDate, endDate);
        if(response == null) {
            return getJsonp(callback,"调用九天达为空!");
        }
        if(response.isSuccess()){
            return getJsonp(callback,response.getQueryInfoSet());
        }
        return  "";
    }

    /** 旅行社销售量统计接口
     * @param startDate yyyy-MM-dd
     * @param endDate yyyy-MM-dd
     * @param callback
     * @return
     */
    @RequestMapping(params = { "method=travelSalesByDay" })
    @ResponseBody()
    public String travelSalesByDay(String startDate,String endDate,String callback) {
        TicketbizResponse<TravelSalesModel> response = ticketbizService.travelSalesByDay(startDate, endDate);
        if(response == null) {
            return getJsonp(callback,"调用九天达为空!");
        }
        if(response.isSuccess()){
            return getJsonp(callback,response.getQueryInfoSet());
        }
        return  "";
    }
}
